package itheima.com.zuoye.d02;


import java.util.Scanner;

public class Test {

        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入支付方式：[WeChat,Ali,Bank]");
            String type = sc.next();
            System.out.println("请输入支付金额：");
            int money = sc.nextInt();
            // 通过工厂类中的方法，获取支付对象，并调用支付方法完成支付
            Payment payment = Factory.getInstance(type);
            payment.pay( money);
            System.out.println("支付完成");

            // 【此处完成代码】
        }
    }




    // 工厂类，专门负责创建对象
//
    class Factory{
        public   static Payment getInstance(String type){
            if(type== null){
                return null;
            }

            Payment  payment = null;
            switch (type){
                case"wechat":
                    payment = new WechatPay();
                    break;
                case"Ali":
                    payment = new AliPay();
                    break;
                case"bank":
                    payment = new BankPay();
                    break;
            }
            return payment;
        }
    }





    interface Payment {
        void pay(int money);
    }


    class WechatPay implements Payment {
        public void pay(int money) {
            System.out.println("微信支付成功，支付金额：" + money);
        }
    }
    class AliPay implements Payment {
        public void pay(int money) {
            System.out.println("支付宝支付成功，支付金额：" + money);
        }
    }
    class BankPay implements Payment {
        public void pay(int money) {
            System.out.println("银行卡支付成功，支付金额：" + money);
        }
    }

